package com.leyou.common.advice;

import com.leyou.common.exception.LyException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @ClassName : ControllerExceptionAdvice  //类名
 * @Description : 异常处理器  //描述
 * @Author : qingfeng  //作者
 * @Date: 2020-09-15 07:21  //时间
 */
//添加了@controlleradvice的类，默认会拦截@controller的类
@ControllerAdvice
@Slf4j
public class ControllerExceptionAdvice {
    /**
     * @Description //TODO 统一异常处理方法，@ExceptionHandler（runtimeException.class)声明这个方法处理runtime异常
     * @Param
     * @return
     */
    @ExceptionHandler(LyException.class)
    public ResponseEntity<String> handleLyException(LyException e){
        return ResponseEntity.status(e.getStatus()).body(e.getMessage());
    }
}
